﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Ecreate.Web.popedom
{
    public partial class menulist : System.Web.UI.Page
    {
        public string str_xml = "";
        Ecreate.Popedom.Service.IMenuService menuService = new Ecreate.Popedom.Service.SpringImpl.MenuServiceImpl();
        Ecreate.Popedom.Service.IGroupService groupService = new Ecreate.Popedom.Service.SpringImpl.GroupServiceImpl();
        protected void Page_Load(object sender, EventArgs e)
        {
            string groupid = this.Request.QueryString["groupid"];
            if (!String.IsNullOrEmpty(groupid))
            {
                this.str_xml = menuService.getXmlStringByGroupId(long.Parse(groupid));
                hid_groupid.Value = groupid;
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string value = HtmlHelper.getPostValue(this);
            string[] IdArray = value.Split(',');
            IList<Ecreate.Popedom.tGroupassign> Groupassign = new List<Ecreate.Popedom.tGroupassign>();
            Ecreate.Popedom.tGroup group = groupService.getById(long.Parse(this.hid_groupid.Value));
            foreach (string id in IdArray)
            {
                if (id.Trim() == "") continue;
                Ecreate.Popedom.tGroupassign assign = new Ecreate.Popedom.tGroupassign();
                Ecreate.Popedom.tMenu menu = menuService.getById(id);
                assign.Menu = menu;
                assign.Group = group;
                Groupassign.Add(assign);
            }
            groupService.UpdateMenusByGroupId(group.Id, Groupassign);
            this.str_xml = menuService.getXmlStringByGroupId(group.Id);
        }
    }
}
